home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!usenet
- From: Gertjan Klein <gklein@xs4all.nl>
- Newsgroups: comp.lang.c
- Subject: Re: Please help ?!
- Date: 22 Jan 1996 11:15:16 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4dvrk4$f2d@news.xs4all.nl>
- References: <4dm889$3hs@neptunus.pi.net> <4drnv1$cr@news.iag.net>
- NNTP-Posting-Host: xs1.xs4all.nl
-
- In article <4drnv1$cr@news.iag.net>, jatmon@iag.net (John R Buchan) wrote:
-
- [Correction of someone else's code, mostly snipped]
-
- I have a question about this specific fragment of code, in particular
- the last line of it.
-
- > do
- > {
- > *cpy++ = *cmd++;
- > }
- > while (!strchr(" /-\0", *cmd));
-
- Why do you include a '\0' in the string? (If this was the original
- poster's code, the question changes to: Why did you leave it in?) It
- doesn't make much sense to me, as '\0' is the string terminator, and it
- is already there. I.e., the following code:
-
- #include <stdio.h>
- #include <string.h>
-
- int main(void) {
-
- int c = '\0';
-
- printf("Character %sfound in string.\n",
- strchr(" /-", c) ? "" : "not ");
- return 0;
- }
-
- ... displays "Character found in string." whether I include the '\0'
- or not. The basic question is, is the terminating zero regarded part of
- the string here? My implementation's strchr() seems to imply it is, but
- I'd like to know if this always the case. I couldn't find anything in
- K&R2 about how strchr() behaves when the int to search for is 0. What's
- to keep it from first checking for the string terminator before doing
- the compare? (In either case, including the '\0' in the string wouldn't
- make a difference, would it?)
-
- Gertjan.
-
- ---
- --
- Gertjan Klein <gklein@xs4all.nl>
-